#ifndef SWARMMESSAGE_H
#define SWARMMESSAGE_H
/** /file */

#include <string>
#include <vector>
#include "Network.h"

namespace SwarmOS{

using std::string;
using std::vector;

// message prefixes
const string OS_INSTRUCTION = "OS:";
const string AL_INSTRUCTION = "AL:";

// software message prefixes/headers
const string SWARM_DATA = "**D@A:";
const string NET_DATA = SWARM_DATA + "NET:";
const string DEBUG_HDR = SWARM_DATA + "DEBUG INFO";
const string DEBUG_IMG_HDR = SWARM_DATA + "DEBUG IMAGES";

// OS command strings
const string FORWARD = "FORWARD";
const string FD = "FD";
//const string BACK = "BACK"; // defined in peripherals
const string BK = "BK";
//const string RIGHT = "RIGHT"; // defined in peripherals
const string RT = "RT";
//const string LEFT = "LEFT"; // defined in peripherals
const string LT = "LT";
const string SPIN = "SPIN";
const string TURN = "TURN";
const string HALT = "HALT";
const string DEBUG = "DEBUG";
const string DEBUGIMG = "DEBUGIMG";
const string RESUME = "RESUME";
const string RAW = "RAW"; // raw SPI command
const string GET = "GET"; // get and
const string SET = "SET"; // set SPI peripherals
const string RECONNECT = "RECONNECT"; // network
const string RESPI = "RESPI"; // reset SPI
const string RELAY = "RELAY"; // inter-robot comm diagnostic
const string STOP = "STOP";

// net data
const string NET_DATA_ID = NET_DATA + "ID:";
const string NET_DATA_IP = NET_DATA + "IP:";
const string NET_DATA_IP_SIZE = NET_DATA + "IP_SIZE:";
const string NET_DATA_ACK = NET_DATA + "ACK:";
const string NET_DATA_DONE = NET_DATA + "DONE";

// peripheral names (for OS:GETs and :SETs)
const string RED = "RED";
const string BLUE = "BLUE";
const string GREEN = "GREEN";
const string RIGHT = "RIGHT";
const string LEFT = "LEFT";
const string FRONT = "FRONT";
const string BACK = "BACK";

const int HOST_ID = 0;

// function list for useNetwork:
const int CONSTRUCT  = 0;
const int DESTRUCT   = 1;
const int REASSIGN   = 2; // reassign message vectors
const int WRITE      = 3;
const int BROADCAST  = 4;
const int REFRESH    = 5; // refresh message vectors
const int RECONN     = 6; // reconnect all this robot's sockets
const int GET_SIZE   = 7;
const int GET_ID     = 8;
const int GET_IP     = 9;
const int GET_IS_CON = 10;

int useNetwork(
	int functions,
	vector<vector<string> > * swarmOSMessages = NULL,
	vector<vector<string> > * algorithmMessages = NULL, 
	string message = "", string *ip = NULL, int botnum = -1);

inline void destroyNetwork(){
	useNetwork(DESTRUCT);
}

inline int writeMessage(int botnum, string mess){
	return useNetwork(WRITE, NULL,NULL, mess,NULL,botnum);
}

inline int writeMessage(string ip, string message){
	return useNetwork(WRITE, NULL,NULL,message,&ip);
}

inline void broadcast(string message){
	useNetwork(BROADCAST, NULL,NULL,message);
}

inline void reconnectAll(){
	useNetwork(RECONN);
} 

inline void refreshNetworkMessages(){
	useNetwork(REFRESH);
} 

inline int getSwarmSize(){
	return useNetwork(GET_SIZE);
}

inline int getNetworkID(){
	return useNetwork(GET_ID);
}

inline string getIP(){
    string ip;
	useNetwork(GET_IP, NULL, NULL, "", &ip);
    return ip;
}

inline string getIP(int botnum){
    string ip;
	useNetwork(GET_IP, NULL, NULL, "", &ip, botnum);
    return ip;
}

inline int getIsConnected(int botnum){
	return useNetwork(GET_IS_CON, NULL,NULL,"",NULL,botnum);
}

}
#endif //SWARMMESSAGE_H
